<?php
namespace Hive\Mission;
use Hive\Mission;
use Doctrine\DBAL\Connection;

/**
 * Announce Object.
 *
 * The announce  is the HTML announce that should be display in an output
 * target web site
 *
 * @author Xavier VILAIN
 * @package mission
 * @property int 	$announceid 		Announce Id
 * @property int 	$missionid			Id of the mission
 * @property int 	$type				Type of announce
 * @property string $text				Annouce HTML text
 * @property bool 	$loekz 				Deletion Flag if true is an been deleted
 */
class Announce extends \Fox\Object {

	/**
	 * Link to the ressource
	 * @var string
	 */
	const LINK_MISSION = 'mission';

	/**
	 *
	 * Return Object Content for Search Engine
	 */
	public function content() {
		$data = parent::getNonProtectedData();
		return implode(',',$data);
	}

	/**
	 * (non-PHPdoc)
	 * @see Fox.Object::beforeCreate()
	 */
	protected function beforeCreate() {
		$this->cdate = $this->udate = self::sqlDateTime(time());
		$this->cname = $this->uname = \User::current()->getId();
	}

	/**
	 * (non-PHPdoc)
	 * @see Fox\Object.Versioned::afterCreate()
	 */
	protected function afterCreate()
	{
		// Add to the search engine
		//$searchEngine = new \Fox\SearchEngine();
		//$searchEngine->add($this,$this->missionid,Mission::classname());
	}

	/**
	 * (non-PHPdoc)
	 * @see Fox\Object.Versioned::beforeUpdate()
	 */
	protected function beforeUpdate($changed) {
		if($changed) {
			$this->udate = self::sqlDateTime(time());
		    $this->uname = \User::current()->getId();
		}
	}
	
	/**
	 * (non-PHPdoc)
	 * @see includes/classes/Fox/Object/Fox/Object/Versioned::afterVersionUpdate()
	 */
	protected function afterUpdate() {
		// Add to the search engine
		//$searchEngine = new \Fox\SearchEngine();
		//$searchEngine->synchronize($this,$this->missionid,Mission::classname());
	}

	/**
	 * (non-PHPdoc)
	 * @see Fox.Object::delete()
	 */
	public function delete() {
		parent::delete();
		//$searchEngine = new \Fox\SearchEngine();
		//$searchEngine->delete($this,$this->missionid,Mission::classname());
	}
}
\Fox\Dao::infos(
	Announce::className(),
	new \Fox\Object\Info('mission_announces', \Fox\Databases::DB_APP)
);